package com.azthink.chapter423.controller;


import com.azthink.chapter423.utils.ResultGenerator;
import com.azthink.chapter423.vo.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/api/hello")
public class HelloController {

    //http://localhost:8088/api/hello/say?name=AOP
    @GetMapping(value = "/say")
    public Result<String> say(@RequestParam String name){

        //模拟异常信息
        /*try {
            int a = 2;
            int b = 0;
            int c = a / b;
            System.out.println(c);
            return ResultGenerator.ok("Hello, " + name + c);
        }catch (Exception e){

*//*            {
                "message": "未知错误，请联系系统管理员",
                    "data": "错误信息：/ by zero",
                    "status": 500
            }*//*

            return ResultGenerator.fail500(e.getMessage());
        }*/
/*
        {
            "timestamp": 1526372839259,
                "status": 500,
                "error": "Internal Server Error",
                "exception": "java.lang.ArithmeticException",
                "message": "/ by zero",
                "path": "/api/hello/say"
        }*/

        int a = 2;
        int b = 0;
        int c = a / b;
        System.out.println(c);
        return ResultGenerator.ok("Hello, " + name + c);

    }




    /*@ExceptionHandler(Exception.class)
    public Result exceptionHandler(){
        return ResultGenerator.fail();
    }*/
}
